/*
 * @Author: 北极星 8518826+liu-chaofans@user.noreply.gitee.com
 * @Date: 2023-11-17 10:47:10
 * @LastEditors: 北极星 8518826+liu-chaofans@user.noreply.gitee.com
 * @LastEditTime: 2023-12-16 22:29:54
 * @FilePath: /chatServer/include/server.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2023-11-17 10:47:10
 * @LastEditors: 北极星 8518826+liu-chaofans@user.noreply.gitee.com
 * @LastEditTime: 2023-12-14 20:28:11
 * @FilePath: /chatServer/include/server.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#ifndef SERVER_H
#define SERVER_H
#include <iostream>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <arpa/inet.h>
#include <vector>
#include <mysql_connection.h>
#include <mysql_driver.h>
#include <cppconn/driver.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <map>
#include "string.h"

#include "msg.h"
using namespace sql;

class Server
{
private:
    int _serverSocket;
    std::vector<OnLineUserList> _clientSockfds;
    Driver *driver = NULL;
    Connection *con = NULL;
    //std::map<char * username,int socket> users_map;

public:
    Server();
    ~Server();

    int InitSocket();
    int Bind(unsigned short port);
    int Listen();
    int Accept();
    int Connect2DB();
    int OnRun();
    int IsRun();

   
    int DealRegInfoFunction(char *buffer, int socket);
    int DealRequestUserinfo(char *buffer, int socket);
    int DealBigFile(char *buffer, int socket);
    int DealLoginFunction(char *buffer, int socket);
    int DealLogonFunction(char *buffer, int socket);
    int DealRequestList(char *buffer, int socket);
    int DealChatToFriend(char *buffer, int socket);
    void DealUnknownMsg(char *buffer);
    void DealGetMsg(char *buffer,int socket);
    void DealGetUser(char *pbuffer,const  char *name,char * nbuffer = NULL,char * ibuffer = NULL);
    void DealRequstAddFriend(char *pbuffer,int socket);
};

#endif